<template>
  <div>
    <!-- 搜索栏区域 -->
    <el-card class="SearchCard" body-style="padding:0px">
      <el-row>
        <el-col :span="2">
          <div class="SearchTitle">条件搜索栏</div>
        </el-col>
        <el-col :span="4">
          <el-row>
            <el-col :span="10">
              <div class="SearchLable">搜索关键字</div>
            </el-col>

            <el-col :span="14">
              <div class="SearchLable">
                <el-input placeholder="请输入内容" v-model="queryInfo.srm" clearable></el-input>
              </div>
            </el-col>
          </el-row>
        </el-col>
        <el-col :span="2">
          <div class="SearchLable">
            <el-button size="medium" type="primary" @click="getSearchList()">搜索</el-button>
          </div>
        </el-col>
        <el-col :span="2">
          <div class="SearchLable">
            <el-button size="medium" @click="addNewDictLabOne = true" type="primary">新增检验项目</el-button>
          </div>
        </el-col>
      </el-row>
    </el-card>
    <el-card class="TableCard" :body-style="{ padding: '0px' }">
      <div>
        <el-table
          :data="TableData"
          border
          :header-cell-style="{ 'text-align':'center',background: '#3F9DFD', color: '#FFF' }"
          :cell-style="{'text-align':'center'}"
          size="medium"
          stripe
          style="width: 100%;font-size:12px"
        >
          <el-table-column prop="labcode" label="检验编码" width="100"></el-table-column>

          <el-table-column prop="name" label="操作" width="60">
            <template slot-scope="scope">
              <el-button type="text" size="mini" @click="showDictLabOne(scope.row.id)">编辑</el-button>
            </template>
          </el-table-column>
          <el-table-column prop="labname" label="检验项目名称"></el-table-column>
          <el-table-column prop="type" label="检验类型" width="200">
            <template
              slot-scope="scope"
            >{{(scope.row.type==1)?"病原学检测":(scope.row.type==2)?"药敏试验":(scope.row.type==3)?"病原学检测+药敏实验":"其他"}}</template>
          </el-table-column>
          <el-table-column prop="searchcode" label="搜索码" width="100"></el-table-column>
        </el-table>
        <!-- 0其它1病原学检测2药敏实验3病原学检测+药敏实验 -->
      </div>
      <div class="block">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="queryInfo.page"
          :page-sizes="[20, 50, 100]"
          :page-size="queryInfo.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="this.total"
          background
        ></el-pagination>
      </div>
    </el-card>
    <el-dialog
      title="添加新药"
      :visible.sync="addNewDictLabOne"
      width="30%"
      :before-close="handleClose"
    >
      <el-card>
        <el-form
          label-position="right"
          label-width="120px"
          class="demo-form-inline addForm"
          :model="addNewDictLabDate"
        >
          <el-form-item label="检验项目编码">
            <el-input v-model="addNewDictLabDate.labcode"></el-input>
          </el-form-item>
          <el-form-item label="检验项目名称">
            <el-input v-model="addNewDictLabDate.labname"></el-input>
          </el-form-item>
          <el-form-item label="类别">
            <el-select v-model="addNewDictLabDate.type" placeholder="请选择">
              <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-form>
      </el-card>

      <span slot="footer" class="dialog-footer">
        <el-button type="primary" size="mini" @click="addNewDictLab()">新增</el-button>
        <el-button size="mini" @click="dialogVisible = false">关闭</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import { getDictLabAllList, addNewDictLab, showDictLabOne } from "@/api/rad";
export default {
  data() {
    return {
      queryInfo: {
        srm: "",
        pageList: 1,
        pageSize: 20
      },
      total: 0,
      TableData: [],
      addNewDictLabOne: false,
      addNewDictLabDate: {
        labcode: "",
        labname: "",
        type: ""
      },
      // 检验类型0其它1病原学检测2药敏实验3病原学检测+药敏实验
      options: [
        {
          value: 1,
          label: "病原学检测"
        },
        {
          value: 2,
          label: "药敏实验"
        },
        {
          value: 3,
          label: "病原学检测+药敏实验"
        },
        {
          value: 0,
          label: "其他"
        }
      ],
      updataDictLabData: {
        id: "",
        labcode: "",
        labname: "",
        type: ""
      }
    };
  },
  created: function() {
    this.getDictLabAllList();
  },
  methods: {
    handleClose(done) {
      this.$confirm("确认关闭？")
        .then(_ => {
          done();
        })
        .catch(_ => {});
    },
    handleSizeChange(newSize) {
      this.queryInfo.pageSize = newSize;
    },

    handleCurrentChange(newPage) {
      this.queryInfo.pageList = newPage;
    },
    async getDictLabAllList() {
      let res = await this.$rad.getDictLabAllList({
        srm: this.queryInfo.srm,
        pageList: this.queryInfo.pageList,
        pageSize: this.queryInfo.pageSize
      });
      this.total = res.total;
      console.log(res);
      this.TableData = res.rows;
    },
    async addNewDictLab() {
      console.log(this.addNewDictLabDate);

      let res = await this.$rad.addNewDictLab({
        labcode: this.addNewDictLabDate.labcode,
        labname: this.addNewDictLabDate.labname,
        type: this.addNewDictLabDate.type
      });
      console.log(res);
      if (res.code == 1) {
        this.$message.success(res.msg);
        this.addNewDictLabDate.labcode = "";
        this.addNewDictLabDate.labname = "";
        this.addNewDictLabDate.type = " ";
        this.addNewDictLabOne = false;
        this.getDictLabAllList();
      } else {
        this.$message.error(res.msg);
      }
    },
    async showDictLabOne(id) {
      this.updataDictLabData.id = id;
      let res = await this.$rad.showDictLabOne({
        id: id
      });

      this.updataDictLabData.labcode = res.data.labcode;
      this.updataDictLabData.labname = res.data.labname;
      this.updataDictLabData.type = res.data.type;
      // 接口出错///////////////////////////////////////////////
    },
    getSearchList() {
      console.log(this.queryInfo);
      this.queryInfo.pageList = 1;
      this.getDictLabAllList();
    }
  }
};
</script>
<style scoped>
.SearchCard {
  height: 50px;
  font-size: 12px;
}
.SearchTitle {
  height: 50px;
  display: flex;
  justify-content: center;
  align-items: center;
  border-right: 1px solid #c2c2c2;
}
.SearchLable {
  height: 50px;
  display: flex;
  justify-content: center;
  align-items: center;
}
.TableCard {
  margin-left: 3px;
  margin-top: 2px;
}
.block {
  text-align: center;
  margin-top: 12px;
  margin-bottom: 12px;
}
.addForm >>> .el-form-item__content {
  width: 200px;
  /* margin-left: 120px; */
}
</style>